<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
</head>

<body>
    <input type="text" id="text">
    <script>
        var arr = [{
                name: "你是谁,他在那里",
                id: 1102
            },
            {
                name: "圈住你在那里",
                id: 1102
            },
            {
                name: "hello在那里",
                id: 1102
            },
            {
                name: "怪你",
                id: 1102
            },
            {
                name: "world",
                id: 1102
            },
        ]

        let tx = document.getElementById("text");
        tx.onkeydown = function(event){
            console.log(this.value);
            if(event.keyCode==13 && this.value!=""){
                var res = arr.filter(item=>item.name.includes(this.value));
                var result = res.map(item =>{
                    if (item.name.length > 5){
                        item.name = item.name.slice(0,5)+"...";
                    }
                    return item;
                    
                })
                console.log(...result);
            }
        }
    </script>
</body>

</html>